use v6.d;

unit role Tabular;

    use DB;
	use DB::Result;
	use Rule::Table;
	
	# DDL语句
        has Str $.ddl is required;
        has Str $.source is required;
	
	# 连接数据库 
	# Praram: $source -- Data Source Name
	# Return: DB 对象
	method connect( --> DB::Connection) { ... }

	# 表名
	method table-name() {
        my $ddl = self.ddl;
	    my $table-name = Rule::Table.parse($ddl).<table-name>.Str;
	    return $table-name;
	}

	# 初始化表
	# Param: 
	# Return: Bool值 -- True | False
	method init(Str $source --> Bool) { ... }

	# 选择列
	# Param:  @columns -- 列名
	#         $where   -- 选择条件 哈希值 {$column-name => $value}
	# Return: ResultSet 对象
	method select( @columns, $where --> DB::Result) { ... }

	# 更新列
	# Param:  %hashes -- 更新的列名及值的哈希对 { $column-name => $value}
	#         $where  -- 选择条件 哈希值 { $column-name => $value }
	# Return: Int值   -- 已更新的行数
	method update(Pair $kv, Pair $where --> Int) {...}

	# 删除列
	# Param:  $where  -- 选择条件 哈希值 {$column-name => $value}
	# Return: Int值   -- 已删除的行数
	method delete(Pair $where) returns Int {...}

	# 插入数据
	# Param:  @columns -- 插入数据的列名
	#         @values  -- 插入数据的值
	# Return: Int值    -- 已插入的行数 
	method insert( Str @columns, @values --> Int) {...}

	# 关闭数据库连接
	method finish() {
	    self.connect.finish;
	}

